package com.vo;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
@ChannelHandler.Sharable
public class NettyClientHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("Client,channelActive");
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
//        ByteBuf buf = (ByteBuf) msg;
//        byte[] buffer = new byte[buf.readableBytes()];
//        buf.readBytes(buffer);
//        String message = new String(buffer,"utf-8");
//        System.out.println("Client,接收到服务端发来的消息:" + message);
        ProtoMsg.MessageRequest data = (ProtoMsg.MessageRequest) msg;
        System.out.println("data.getKey() = " + data.getKey());
        System.out.println("data.getData() = " + data.getData());
        System.out.println("data.getStatus() = " + data.getStatus());
        System.out.println("Client,接收到服务端发来的消息:" + msg);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        System.out.println("Client,exceptionCaught");
        cause.printStackTrace();
    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("Client,channelInactive");
    }

}